package com.qing.common.utils.json.hutool;


import cn.hutool.json.JSONUtil;

public class TestJson {

    public static void main(String[] args) {
        // 对象转json串
        BeanWithEnum testJson = new BeanWithEnum().setAge(21).setName("zhangsan").setConvertorEnum(ConvertorEnum.VALUE1);
        String jsonStr = JSONUtil.toJsonStr(testJson);
        System.out.println("=========对象转换的Json串: ");
        System.out.println(jsonStr);

        // json串转对象
        jsonStr = "{\"age\":21,\"name\":\"zhangsan\",\"convertorEnum\":\"value2\"}";
        BeanWithEnum toBean = JSONUtil.toBean(jsonStr, BeanWithEnum.class);
        System.out.println("==========Json串转换的对象: ");
        System.out.println(toBean);
    }

}
